// pages/updatepwd/updatepwd.js
var app = getApp()
  Page({
    data:{
      userInfoList:{},
       oldPassword:'',
       Password1:'',
       Password2:''
    },
    onLoad:function(){
     this.setData({
       userId:getApp().globalData.Id
     })
   },
    p1:function(e){
      this.setData({
       oldPassword:e.detail.value
      })
    },
    p2:function(e){
      this.setData({
        Password1:e.detail.value
      })
    },
    p3:function(e){
      this.setData({
       Password2:e.detail.value
      })
    },
    submit:function(e){
      if(this.data.Password1==this.data.Password2&&this.data.oldPassword==app.globalData.userInfoList.userPwd){
        wx.request({
          url: app.globalData.url+'alterUserPwdAction',
          data:{
            userId:app.globalData.userInfoList.userId,
            userPwd:this.data.Password1
          },
         success(e){
           wx.showToast({
             title: '修改成功',
             icon:'none'
           })
           wx.reLaunch({
             url: '../mine/mine',
           })
         }
        })
      }else{
        wx.showToast({
          title: '原密码错误或两次密码不一致',
          icon:'none'
        })
      }
     }
 })